﻿
function MainViewModel() {
    // Declare all properties before RegisterViewModel
    this.firstName = "Rajnish";
    this.lastName = "Noonia";
    this.time = new Date().getSeconds();
    this.caption = this.lastName +' ' + new Date().getSeconds();
    var that = this;

    // execute and canexecute command
    this.showCommand = new DelegateCommand(
        function(parameter) { alert(that.firstName + " " + that.lastName + " is Great"); },
        function(parameter) { return that.firstName != null && that.firstName.length > 5; }
    );
   
    setInterval(function() {
        that.time = new Date().getMilliseconds();
    }, 5);

    OneApp.RegisterViewModel(this);

    this.base.OnPropertyChanged = function (propertyName) {
        if (propertyName == "firstName") {
            that.base.RaisePropertyChanged("showCommand");
        } else if (propertyName == "lastName" || propertyName == "time") {
            if (that.lastName == null) {
                that.caption = that.time;
            } else {
                that.caption = that.lastName + " " + that.time;
            }
        }
    }
};

// Static resource
var viewModel = new MainViewModel();
